package xuhaijia.lanou3g.autohome.recommend.talker;
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                   \\`.
//        .'//            为什么坚持  想一想当初             \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-.  \\`.
//    .'//.-"                 `-.  |  .-'                 "-. \\`.
//  .'//______.============-..   \ | /   ..-============._______\\`.
//.'//____________________________\|/_____________________________\\`.
// 
//                             

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import xuhaijia.lanou3g.autohome.R;
import xuhaijia.lanou3g.autohome.base.NetTool;
import xuhaijia.lanou3g.autohome.recommend.recommendreusing.RecommendBean;

/**
 * Created by 7 on 16/8/19.
 */
public class TalkerAdapter extends BaseAdapter{
    private Context context;
    private TalkerBean talkerBean;

    public TalkerAdapter(Context context) {
        this.context = context;
    }

    public void setTalkerBean(TalkerBean talkerBean) {
        this.talkerBean = talkerBean;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (talkerBean.getResult().getList() == null) {
            return 0;
        }
        return talkerBean.getResult().getList().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_recsame, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        TalkerBean.ResultBean.ListBean bean = talkerBean.getResult().getList().get(position);
        viewHolder.titleTv.setText(bean.getTitle());
        viewHolder.dateTv.setText(bean.getTime());
        viewHolder.historyTv.setText(bean.getReplycount() + "评论");
        NetTool mNetTool = new NetTool();
        mNetTool.getImage(bean.getSmallpic() , viewHolder.iv);



        return convertView;
    }

    private class ViewHolder {
        TextView titleTv;
        TextView dateTv;
        TextView historyTv;
        ImageView iv;

        public ViewHolder(View view) {
            titleTv = (TextView) view.findViewById(R.id.item_recsame_title);
            dateTv = (TextView) view.findViewById(R.id.item_recsame_date);
            historyTv = (TextView) view.findViewById(R.id.item_recsame_history);
            iv = (ImageView) view.findViewById(R.id.item_recsame_iv);
        }
    }
}
